#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 4e5 + 5;

mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int n, m;
int ans1[N], ans2[N];
int f[N], sz[N];
int st[N], top;
char t[N];
int x[N], y[N];
vector<pii> tr[N << 2];
void init() {
  rep(i, 1, n) f[i] = i, sz[i] = 1;
  top = 0;
}
int find(int x) { return f[x] == x ? x : find(f[x]); }
bool merge(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx == fy) return false;
  if (sz[fx] < sz[fy]) swap(fx, fy);
  sz[fx] += sz[fy];
  f[fy] = fx;
  st[++top] = fy;
  return true;
}
void back(int s) {
  while (top > s) {
    int fy = st[top];
    int fx = f[fy];
    sz[fx] -= sz[fy];
    f[fy] = fy;
    top--;
  }
}
void add(int L, int R, pii x, int p = 1, int l = 1, int r = m) {
  if (L <= l && R >= r) {
    tr[p].push_back(x);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) add(L, R, x, p << 1, l, mid);
  if (R > mid) add(L, R, x, p << 1 | 1, mid + 1, r);
}
void solve(int ans[N], int p = 1, int l = 1, int r = m, int now = n) {
  int old = top;
  for (pii x : tr[p]) now -= merge(x.first, x.second);
  if (l == r) {
    ans[l] = now;
    back(old);
    return;
  }
  int mid = (l + r) >> 1;
  solve(ans, p << 1, l, mid, now);
  solve(ans, p << 1 | 1, mid + 1, r, now);
  back(old);
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, m) {
    cin >> t[i] >> x[i] >> y[i];
    if (x[i] > y[i]) swap(x[i], y[i]);
  }
  init();
  map<pii, int> mp;
  rep(i, 1, m) {
    if (t[i] == 'B') continue;
    pii p = pii(x[i], y[i]);
    if (mp[p] == 0)
      mp[p] = i;
    else
      add(mp[p], i - 1, p), mp[p] = 0;
  }
  for (auto p : mp)
    if (p.second) add(p.second, m, p.first);
  solve(ans1);
  mp.clear();
  rep(i, 1, m) {
    if (t[i] == 'A') continue;
    pii p = pii(x[i], y[i]);
    if (mp[p] == 0)
      mp[p] = i;
    else
      add(mp[p], i - 1, p), mp[p] = 0;
  }
  for (auto p : mp)
    if (p.second) add(p.second, m, p.first);
  solve(ans2);
  rep(i, 1, m) cout << ans1[i] - ans2[i] << endl;
  return 0;
}